package db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class Oppstart {
	
	/**DBManager class for interaction with the database*/
	private static Db  dbm = Db.getInstance();
	/**The Connection for interaction with the database*/
	//private static Connection con = dbm.getConnection();
	
	public static List<WellReg> getAllWells() throws SQLException {
		List<WellReg> liste = new ArrayList<WellReg>();
		String query = "SELECT * FROM Well order by wellId;";
		ResultSet rs = dbm.executeQuery(query);
		while (rs.next()){
			
			int wellId		= rs.getInt(1);
			int IWSId 	= rs.getInt(2);
			double R0  = rs.getDouble(3);
			double R1  = rs.getDouble(4);
			double P1 = rs.getDouble(5);
			double T1 = rs.getDouble(6);
			
			liste.add(new WellReg(wellId, IWSId, R0, R1, 
					P1, T1));
		}
		System.out.println(liste);
		return liste;
	}
	
	public static List<PlatformReg> getAllPlatforms() throws SQLException {
		List<PlatformReg> liste = new ArrayList<PlatformReg>();
		String query = "SELECT * FROM Platform ORDER BY platformId;";
		ResultSet rs = dbm.executeQuery(query);
		while (rs.next()){
			
			int IWSId 	= rs.getInt(1);
			int platformId = rs.getInt(2);
			String name = rs.getString(3);
			
			liste.add(new PlatformReg(platformId,name));
		}
		System.out.println(liste);
		return liste;
	}
	
	public static List<LocalWatchSystemReg> getLocalWatchSystems() throws SQLException {
		List<LocalWatchSystemReg> liste = new ArrayList<LocalWatchSystemReg>();
		String query = "SELECT * FROM LocalWatchSystem;";
		ResultSet rs = dbm.executeQuery(query);
		while (rs.next()){
			
			int IWSId 	= rs.getInt(1);
			int platformId = rs.getInt(2);
			int T = rs.getInt(3);
			int wellId = rs.getInt(4);
			
			liste.add(new LocalWatchSystemReg(T));
		}
		System.out.println(liste);
		return liste;
	}
	
	public static List<flowReg> getFlow() throws SQLException{
		List<flowReg> flow = new ArrayList<flowReg>();
		String query = "SELECT * FROM flow;";
		ResultSet rs = dbm.executeQuery(query);
		while(rs.next()){
			
			double temprature = rs.getDouble(1);
			double sandContent = rs.getDouble(2);
			double pressure = rs.getDouble(3);
			double velocity = rs.getDouble(4);
			
			flow.add(new flowReg(temprature, sandContent, pressure, velocity));
		}
		System.out.println(flow);
		return flow;
	}

	public static void main(String [] args){
		try {
			getAllWells();
			getAllPlatforms();
			getFlow();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
